<!-- 详情页 -->
<template>
    <div class="column-detail-page w-75 mx-auto">
    <div class="column-info row mb-4 border-bottom pb-4 align-items-center" v-if="column">
      <div class="col-3 text-center">
        <img :src="column.avatar && column.avatar.url" :alt="column.title" class="rounded-circle border w-100">
      </div>
      <div class="col-9">
        <h4>{{column.title}}</h4>
        <p class="text-muted">{{column.description}}</p>
      </div>
    </div>
    <post-list :list="list"></post-list>
  </div>
</template>

<script lang='ts'>
import { defineComponent, PropType, computed, onMounted } from 'vue';
import { useRoute } from 'vue-router'
import { useStore } from 'vuex'
import { GlobalDataProps } from '@/store/index.ts'
// import { testData,  testPosts} from '@/views/testData.ts'
import PostList from '../components/PostList.vue'
export default defineComponent({
   name: 'columnDetail',
   components: {
       PostList
   },

   setup(props) {
       const route = useRoute();
       // 当前专栏id
       const currentId = route.params.id;

       const store = useStore<GlobalDataProps>();
    //    let  testData =  computed( () => store.state.columns);
    //    let testPosts = computed(() => store.state.posts);
    //    console.log("testData.value==", testData.value)
    //    // 头部专栏信息 
    //    const column = testData.value.filter( item => item.id == currentId )[0]
    //    // 获取专栏列表
    //    const list = testPosts.value.filter( item => item.columnId === currentId)
      
      onMounted(() => {
        store.dispatch("fetchColumn", currentId)
        store.dispatch("fetchPosts", currentId)
      })
      // vuex store getters改写
       const column = computed( () => store.getters.getColumnById(currentId))
       const list =  computed( () => store.getters.getPostsByCid(currentId))
       
       return {
           column,
           list
       }
   },
})
</script>
<style lang='scss' scoped>
</style>